<script setup lang="ts">
import type { Knowledge } from "@/types/consult";
import followWithInterest from "@/components/followWithInterest.vue";

const props = defineProps<{ item: Knowledge }>();
//控制关注已关注的数据
const bol = ref(true);

//修改关注未关注按钮的状态
function changeBol() {
  bol.value = !bol.value;
}
function toArticleDetails() {
  uni.navigateTo({ url: `/pages/ArticleDetails/index?id=${props.item._id}` });
}
</script>

<template>
  <view class="knowledge-card van-hairline--bottom">
    <view class="head">
      <view class="items-center flex" @click="toArticleDetails">
        <wd-img round :src="props.item.creatorAvatar" class="avatar" />
        <view class="info">
          <text class="name">{{ props.item.creatorName }}</text>
          <wd-text
            :text="
              props.item.creatorHospitalName +
              ' ' +
              props.item.creatorDep +
              ' ' +
              props.item.creatorTitles
            "
            class="dep"
            :lines="1"
            size="28px"
          ></wd-text>
        </view>
      </view>
      <!-- 关注已关注按钮 -->
      <followWithInterest :bol="props.item.__v" :changeBol="changeBol" />
    </view>
    <view class="body">
      <wd-text
        :text="props.item.title"
        color="#121826"
        :bold="true"
        :lines="1"
        size="32rpx"
        lineHeight="60rpx"
      ></wd-text>
      <wd-text
        :text="'#' + props.item.topics"
        color="#2CB5A5"
        size="24rpx"
        lineHeight="36rpx"
      ></wd-text>

      <wd-text
        :text="props.item.content.replace(/<[^>]+>/g, '')"
        color="#6F6F6F"
        :lines="2"
        size="28rpx"
        lineHeight="48rpx"
      ></wd-text>

      <view class="imgs" :class="{ large: props.item.coverUrl.length === 1 }">
        <wd-img
          v-for="(url, i) in props.item.coverUrl"
          :key="i"
          mode="scaleToFill"
          :src="url"
          :enable-preview="true"
          custom-class="van-image"
        />
      </view>
      <view class="logs">
        <text>{{ props.item.collectionNumber }} 收藏</text>
        <text class="ml-30rpx">{{ props.item.commentNumber }} 评论</text>
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
.knowledge-card {
  width: 690rpx;
  padding-top: 40rpx;
  padding-bottom: 31rpx;
  margin: 0 auto;
  border-bottom: 1rpx solid #efefef;
  .head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .avatar {
      width: 38px;
      height: 38px;
      margin-right: 10px;
    }
    .info {
      width: 450rpx;
      padding-right: 10rpx;
      margin-left: 15rpx;
      .name {
        font-size: 28rpx !important;
        font-weight: regular;
        line-height: 44rpx;
        color: #3c3e42;
        text-align: left;
        letter-spacing: 0rpx;
      }
      .dep {
        font-size: 24rpx !important;
        font-weight: regular;
        line-height: 36rpx;
        color: #c3c3c5;
        text-align: left;
        letter-spacing: 0rpx;
      }
    }
    .btn {
      font-size: 22rpx;
      font-weight: regular;
      line-height: 34rpx;
      color: #2cb5a5;
      text-align: right;
      letter-spacing: 0rpx;
      background-color: #fff;
      border: 2rpx solid #2cb5a5;
      border-radius: 27rpx right;
    }
  }
  .body {
    .title {
      font-size: 32rpx;
      font-weight: medium;
      line-height: 48rpx;
      color: #121826;
      text-align: left;
      letter-spacing: 0rpx;
    }
    .tag {
      margin-top: 6px;
      > span {
        margin-right: 20px;
        font-size: 12px;
        color: var(--cp-primary);
      }
    }
    .intro {
      margin-top: 7px;
      line-height: 2;
      color: var(--cp-text3);
    }
    .imgs {
      display: flex;
      margin-top: 7px;
      .van-image {
        width: 212rpx;
        height: 212rpx;
        margin-right: 12rpx;
        overflow: hidden;
        border-radius: 12rpx;
        &:last-child {
          margin-right: 0;
        }
      }
      &.large {
        .van-image {
          width: 370rpx;
          height: 250rpx;
          background: #c4c4c4;
          border-radius: 30rpx;
        }
      }
    }
    .logs {
      margin-top: 20rpx;
      text {
        font-size: 24rpx;
        font-weight: regular;
        line-height: 38rpx;
        color: #c3c3c5;
        text-align: left;
        letter-spacing: 0rpx;
      }
    }
  }
}
</style>
